package com.dr.java.day04;

/**
 * Created by rui on 2017/12/29.
 */
public class Array1 {
    public static void main(String[] args) {
/*        int[] nums=new int[3];
        System.out.println(nums[1]);*/

        int[][] arr = new int[3][4];
        System.out.println(arr[0][2]);

        int[][] arr1 = new int[3][];
//        System.out.println(arr1[0][4]); 二维上没有定义，所以直接报错

        arr1[0] = new int[4];
        arr1[1] = new int[4];
        arr1[2] = new int[4];
        System.out.println(arr1[2][2]);

        int[] arr2 = {1, 2, 3, 4, 5, 6};
        printArr(arr2);
        printArrAsStr(arr2);
    }

    protected static void printArrAsStr(int[] arr) {
        System.out.print("{");
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]);
            if (i != arr.length - 1) {
                System.out.print(",");
            }
        }
        System.out.print("}");
    }

    static void printArr(int[] arr2) {
        for (int i = 0; i < arr2.length; i++) {
            System.out.println(arr2[i]);
        }
    }
}
